package org.jeecg.modules.openwx;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.jeewx.api.core.exception.WexinReqException;
import org.jeewx.api.third.JwThirdAPI;
import org.jeewx.api.third.model.ApiComponentToken;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class TimeScheduler {
    @Scheduled(cron = "0 0 0/1 * * ?")
    public void timeTask3() {
        /* 核心定时器，每一个小时执行一次*/

        // 先看看是不是已经获取到了ticket
        if (StringUtils.isNotBlank(OpenComponentParams.TICKET)) {
            ApiComponentToken apiComponentToken = new ApiComponentToken();
            apiComponentToken.setComponent_appid(OpenComponentParams.appId);
            apiComponentToken.setComponent_appsecret(OpenComponentParams.secret);
            apiComponentToken.setComponent_verify_ticket(OpenComponentParams.TICKET);
            //微信接口客户端
            try
            {
                String component_access_token = JwThirdAPI.getAccessToken(apiComponentToken);
                //保存获取的token
                OpenComponentParams.ACCESS_TOKEN = component_access_token;
                log.info("保存获取的token:"+OpenComponentParams.ACCESS_TOKEN);
            }
            catch (WexinReqException e) {
                e.printStackTrace();
            }

        }
    }
}
